/*
 * @Author: cl
 * @Description: ''
 * @Date: 2023-04-07 10:23:48
 * @LastEditTime: 2023-04-13 16:38:46
 * @FilePath: \jsnode\nestjs\naota\src\tiger\tiger.controller.ts
 * @LastEditors: cl
 */
import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Version,
  Query,
  HttpCode,
  ParseIntPipe,
  ParseUUIDPipe,
  UseGuards,
  SetMetadata,
} from '@nestjs/common'
import { TigerService } from './tiger.service'
import { CreateTigerDto } from './dto/create-tiger.dto'
import { UpdateTigerDto } from './dto/update-tiger.dto'
import { version } from 'os'
import { log } from 'console'
import { ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger'
import * as uuid from 'uuid'
import { TigerPipe } from './tiger.pipe'
import { Son } from './entities/son.entity'
import { TigerGuard } from './tiger.guard'

// @Controller({
//   path:'/tiger',
//   version:'1'
// })

@Controller('tiger')
@ApiTags('老虎')
// @UseGuards(TigerGuard)
export class TigerController {
  constructor(private readonly tigerService: TigerService) {}

  @Post()
  create(@Body() createTigerDto: CreateTigerDto) {
    console.log('createFun', createTigerDto)
    return this.tigerService.create(createTigerDto)
  }

  @Post('/add/sons')
  addSons(@Body() params: { sons: string[]; tigerId: number }) {
    return this.tigerService.addSons(params)
  }

  @Post('/findPostOne')
  findPostOne(@Body() params: { tigerId: number }) {
    console.log(params)
    return this.tigerService.findPostOne(params)
  }

  @Get('/findAll')
  // @Version('1')
  @SetMetadata('role', ['admin'])
  findAll(): {} {
    return this.tigerService.findAll()
  }

  @Get('/findWhiteOne')
  @HttpCode(500)
  // @Version('1')
  findWhiteOne(@Query('name') name: string, @Query('age') age: number): {} {
    console.log('findWhiteOne:' + name + age)
    return {
      code: 500,
    }
  }

  @Get('/findblackone')
  @ApiOperation({
    summary: '老虎接口',
    description: '这是测试apioperation的接口',
  })
  findBlackOne(@Query('name') name: string, @Query('age') age: number) {
    console.log('findBlackOne:' + name + age)
    return this.tigerService.findBlackOne(name, age)
  }
  @Get(':id')
  findOne(@Param('id', ParseUUIDPipe) id: string) {
    console.log(uuid.v4())
    console.log('findOne:' + id)
    return this.tigerService.findOne(id)
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateTigerDto: UpdateTigerDto) {
    return this.tigerService.update(+id, updateTigerDto)
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.tigerService.remove(+id)
  }
}
